package com.lechuang.goods.controller;

import com.lechuang.common.request.PageRequest;
import com.lechuang.common.result.PageResult;
import com.lechuang.common.result.Result;
import com.lechuang.goods.dto.GoodsListDTO;
import com.lechuang.goods.dto.GoodsSpuSaveDTO;
import com.lechuang.goods.manager.GoodsManager;
import com.lechuang.goods.vo.GoodsDetailSpuVO;
import com.lechuang.goods.vo.GoodsSpuListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "商品管理")
@RequestMapping("/goods")
public class GoodsController {
    @Resource
    private GoodsManager goodsManager;

    @PostMapping("/pageList")
    @Operation(summary = "商品管理-列表")
    public Result<PageResult<GoodsSpuListVO>> pageList(@RequestBody PageRequest<GoodsListDTO> pageRequest){
        PageResult<GoodsSpuListVO> list = goodsManager.pageList(pageRequest);
        return Result.success(list);
    }

    @PostMapping("/saveOrUpdate")
    @Operation(summary = "商品管理-新增、修改")
    public Result<Object> saveOrUpdate(@RequestBody GoodsSpuSaveDTO goodsSpuSaveDTO){
        goodsManager.saveOrUpdate(goodsSpuSaveDTO);
        return Result.success();
    }

    @PostMapping("/delete")
    @Operation(summary = "商品管理-删除")
    public Result<Object> delete(@Schema(description = "spu主键id") @RequestParam Long id){
        goodsManager.delete(id);
        return Result.success();
    }

    @PostMapping("/detail")
    @Operation(summary = "商品管理-详情")
    public Result<GoodsDetailSpuVO> detail(@Schema(description = "spu主键id") @RequestParam Long id){
        GoodsDetailSpuVO detail = goodsManager.detail(id);
        return Result.success(detail);
    }
}
